<template>
  <div class="app-container" v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-form-item label="给我们留言" prop="messages">
        <el-input v-model="form.messages" type="textarea" placeholder="请留下您宝贵的意见500字以内"></el-input>
      </el-form-item>
      <el-form-item label="联系方式(可选)" prop="contactType">
        <el-input v-model="form.contactType" ></el-input>
      </el-form-item>
      <center>
          <el-button type="primary" @click="onSubmit('form')">提交</el-button>
      </center>
    </el-form>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { feedback } from '@/api/systemSetting'
import { parseTime } from '@/utils'
export default {
  name: 'publishActive',
  data() {
    return {
      form: {
        messages: '',
        contactType: ''
      },
      disabled: true,
      rules: {
        messages: [
          { required: true, message: '请留下您的意见', trigger: 'blur' }
        ]
      },
      loading: false
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'roles'
    ])
  },
  created: function() {
  },
  methods: {
    onSubmit(formName) {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.loading = true
          const curTime = new Date()
          const param = {
            'username': this.name,
            'messages': this.form.messages,
            'contactType': this.form.contactType,
            'submitTime': parseTime(curTime.toString())
          }
          feedback(param.username, param.messages, param.contactType, param.submitTime).then(response => {
            this.loading = false
          }).catch(error => {
            console.log(error)
            this.loading = false
            this.$message.error('数据提交失败,请联系管理员')
          })
        } else {
          console.log('error')
        }
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.line{
  text-align: center;
}
</style>

